<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"
    import="java.io.*"
    import="java.io.File" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>File Down</title>
</head>
<body>
<%
	String fileName = request.getParameter("file_name");
	
	String savePath = "upload";
	ServletContext context = getServletContext();
	String sDownloadPath = context.getRealPath(savePath);
	String sFilePath = sDownloadPath + "\\" + fileName;
	
	byte b[] = new byte[4096];
	File oFile = new File(sFilePath);
	
	FileInputStream in = new FileInputStream(sFilePath);
	
	String sMimeType = getServletContext().getMimeType(sFilePath);
	System.out.println("sMimeType>>>"+sMimeType);
	
	if(sMimeType==null)
		sMimeType = "application/octet-stream";
	response.setContentType(sMimeType);
	
	String sEncoding = new String(fileName.getBytes("euc-kr"), "8859_1");
	
	response.setHeader("Content-Disposition", "attachment; filename=" + sEncoding);
	
	ServletOutputStream out2 = response.getOutputStream();
	int numRead;
	
	while((numRead = in.read(b, 0, b.length))!=-1)
	{
		out2.write(b, 0, numRead);
	}
	out2.flush();
	out2.close();
	in.close();
	
	
%>
</body>
</html>